<?php
namespace app\shang\controller;
use think\Controller;
use think\Db;
class Test extends Controller{
    public function index(){
      $res=Db::name('appointment_gym')->field('appoint_time,startime,endtime')->where(array('place_id'=>2,'riqi'=>'2017.11.21'))->select();
      $res_jiqi=array();
      //也就是说将所有的查询出来的进行整理 8:00-12:00 进行变成 8:00-9:00
      
      $res_c=array();
      foreach ($res as $va){
         $res_jiqi[]=$this->fe($va['appoint_time']);
         
         if($va['startime']){
             $res_c[]=$this->fe($va['startime'].":00-".$va['endtime'].":00");
         }
      }
      //$str="8:00-12:00";
      //dump($res_jiqi);

     // dump($res_jiqi);
     $re=[];
    foreach ($res_jiqi as $key=>$va){
       foreach ($va as $key=>$s){
           array_push($re, $s);
       }
    }
  $re2=[];
  foreach ($res_c as $va){
      foreach ($va as $s){
          array_push($re2, $s);
      }
  }
     
     // $res_jiqi=array_count_values($res_jiqi);
    
      //统计出8-9的机械使用情况  8:00-9:00 
      $data=["8-9",'9-10','10-11','11-12'];
      $str='8-9';
      $res=in_array($str, $data);
      if($res){
          dump('ss');
      }
      $s=array();
      $province=array("8-9","9-10","8:00-9:00","10:00-11:00","11:00-12:00");
      $province=array_count_values($re); 
      //统计数组元素出现的次数
      //这个可以了
      dump($province);
     $p=array_count_values($re2);
     $s=array_count_values($s);
     $coxin=array();
     $coxin[0]=$province;
     $coxin[1]=$s;
     dump($p);
     dump($s);
     dump($coxin);
    echo empty($s['8-9'])?0:$s['8-9'];
}
public function fe($str){
    $str=str_ireplace(":00","", $str);
    $data=explode('-', $str);
    $start=$data[0];
    $end=$data[1];
    $res=array();
   
    for ($i=$start;$i<=$end;$i++){
        $s="";
       if($i==$end)break;
       $s.=$i."-".($i+1);
       $res[]=$s;
    }
   
   return $res;
}
public function hebin($data){
    foreach ($data as $key=>$va){
        $r=array_merge($data[$key],$data[$key+1]);
        return $r;
    
    }
}
}